<template>
		<view class="cu-form-group">
			<view class="title">{{label}}</view>
			<picker @change="PickerChange" :value="index" :range="dictOptions" >
				<view class="picker">
					{{index>-1?dictOptions[index]:defaultLabel}}
				</view>
			</picker>
		</view>
</template>

<script>
	export default {
		name: 'JsPicker',
		props: {
			dictCode: {
				type: String,
				default: ''
			},
			value: {
				type: String,
				default: ''
			},
			label: {
				type: String,
				default: ''
			},
			defaultLabel:{
				type: String,
				default: ''
			},
			dataUrl: String
		},
		watch: {
			dictCode: {
				immediate: true,
				handler() {
					this.initDictData()
				},
			},
		},
		computed: {
			
		},
		data() {
			return {
				dictOptions: [],
				index: -1,
				data:{},
				dicValue:''
			}
		},
		methods: {
			initDictData() {
				if(this.dictCode != ''){
					this.$u.api.dictBizData({code: this.dictCode}).then(res => {
						if (typeof res === 'object' && res.result === 'login'){
							return;
						}
						this.dictOptions = this.dictToArray(res.data);
						this.data = res.data.data;
					});
				}else{
					this.dictOptions = this.dictToArray(this.items);
					this.data = res.data.data;
				}
			},
			PickerChange(e) {
				this.index=e.detail.value
				this.dicValue = this.selectDictValue(this.data,this.dictOptions[this.index])
			},
		}
	}
</script>

<style>

</style>
